<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Libs\ConfModel;

final class DbConf extends ConfAbstract
{
    public const PREFIX                         = 'DB.';                // 配置前缀[必定点结尾]
    private string $groupName                   = '';                   // 分组名
    protected bool $ssl                         = false;                // 是否SSL连接
    protected string $host                      = '127.0.0.1';          // 主机地址
    protected int $port                         = 3306;                 // 端口
    protected string $username                  = '';                   // 用户名
    protected string $password                  = '';                   // 密码
    protected string $dbname                    = '';                   // 数据库名
    protected string $prefix                    = '';                   // 数据表前缀
    protected string $charset                   = '';                   // 连接编码
    protected string $collate                   = '';                   // 连接编码字符集
    protected string $logPath                   = '';                   // 日志路径
    protected string $sqlMode                   = '';                   // SQL模式
    protected bool $keepalive                   = false;                // 是否长连接[POOL模式-强制长连接]
    protected int $poolCheckTime                = 30;                   // 检查间隔时长[秒][0-不检查]
    protected int $poolRecycleTime              = 600;                  // 回收最大时长[秒]
    protected int $poolWaitMilliTime            = 100;                  // 等待最大时长[毫秒][0-永远等待]
    protected int $poolStartNum                 = 3;                    // 初始连接数
    protected int $poolMinNum                   = 2;                    // 保持最少连接数
    protected int $poolMaxNum                   = 5;                    // 保持最大连接数

    /**
     * @param array $confData
     * @param string $groupName
     */
    public function __construct(array $confData, string $groupName)
    {
        $this->init($confData);
        $this->groupName = $groupName;
    }

    /**
     * @return string
     */
    public function getGroupName(): string
    {
        return $this->groupName;
    }

    /**
     * @param bool $keepalive
     */
    public function setKeepalive(bool $keepalive):void
    {
        $this->keepalive = $keepalive;
    }

    /**
     * @return bool
     */
    public function isSsl(): bool
    {
        return $this->ssl;
    }

    /**
     * @return string
     */
    public function getHost(): string
    {
        return $this->host;
    }

    /**
     * @return int
     */
    public function getPort(): int
    {
        return $this->port;
    }

    /**
     * @return string
     */
    public function getUsername(): string
    {
        return $this->username;
    }

    /**
     * @return string
     */
    public function getPassword(): string
    {
        return $this->password;
    }

    /**
     * @return string
     */
    public function getDbname(): string
    {
        return $this->dbname;
    }

    /**
     * @return string
     */
    public function getPrefix(): string
    {
        return $this->prefix;
    }

    /**
     * @return string
     */
    public function getCharset(): string
    {
        return $this->charset;
    }

    /**
     * @return string
     */
    public function getCollate(): string
    {
        return $this->collate;
    }

    /**
     * @return string
     */
    public function getLogPath(): string
    {
        return $this->logPath;
    }

    /**
     * @return string
     */
    public function getSqlMode(): string
    {
        return $this->sqlMode;
    }

    /**
     * @return bool
     */
    public function isKeepalive(): bool
    {
        return $this->keepalive;
    }

    /**
     * @return int
     */
    public function getPoolCheckTime(): int
    {
        return $this->poolCheckTime;
    }

    /**
     * @return int
     */
    public function getPoolRecycleTime(): int
    {
        return $this->poolRecycleTime;
    }

    /**
     * @return int
     */
    public function getPoolWaitMilliTime(): int
    {
        return $this->poolWaitMilliTime;
    }

    /**
     * @return int
     */
    public function getPoolStartNum(): int
    {
        return $this->poolStartNum;
    }

    /**
     * @return int
     */
    public function getPoolMinNum(): int
    {
        return $this->poolMinNum;
    }

    /**
     * @return int
     */
    public function getPoolMaxNum(): int
    {
        return $this->poolMaxNum;
    }
}